package com.gustuy.controller;

import com.alibaba.fastjson.JSON;
import com.gustuy.mapper.UserMapper;
import com.gustuy.pojo.User;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
public class Ajax {
    @RequestMapping(value = "/a1",produces = {"application/json;charset=UTF-8"})
    public String ajexgetuser(){
        ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("ApplicationContext.xml");
        UserMapper userMapperImpl = context.getBean("userMapperService", UserMapper.class);
        List<User> users=userMapperImpl.getAllUser();
        System.out.println(users);
        return JSON.toJSONString(users);
    }

    @RequestMapping("/t2")
    public void t2(){
        System.out.println("t2");
    }

    @RequestMapping("/getTime")
    public String getTime(){
        LocalDateTime dateTime =LocalDateTime.now();
        String format = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"));
        return JSON.toJSONString(format);
    }

    @RequestMapping("/upload")
    public String upLoad(){
        return null;
    }
}
